const app = getApp()
Page({

  /**
   * 页面的初始数据
   */
  data: {
    banners: [],
    questions: [],
    section_id: 0
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function(options) {
    var that = this;
    wx.request({
      url: app.globalData.URL + '/kmapping/WebAppAjax/getErrorSubjectList?domain=1&token=' + wx.getStorageSync('token'),
      dataType: 'json',
      method: 'GET',
      data: {
        page: 1,
        num: 10
      },
      success: function(res) {
        var _res = res.data;
        if (_res.error_code == 0) {
          var _banners = _res.data;
          that.setData({
            'banners': _banners,
          })
          that.getWrongTopicList(_banners[0].id);
        }
      }
    })
  },
  getWrongTopicList: function(subjectId) {
    var that = this;
    wx.request({
      url: app.globalData.URL + '/index.php?app=interface&mod=Exam&act=getWrongTopicList&token=' + wx.getStorageSync('token'),
      dataType: 'json',
      method: 'GET',
      data: {
        page: '1',
        num: '10',
        domain: 1,
        subject_id: subjectId
      },
      success: function(res) {
        var _res = res.data;
        if (_res.error_code == 0) {
          var _questions = _res.data;
          that.setData({
            'questions': _questions
          })
        }
      }
    })
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function() {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function() {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function() {

  },
  clickHandle: function(e) {
    var that = this;
    var _banners = that.data.banners;
    this.setData({
      //设置active的值为用户点击按钮的索引值
      section_id: e.currentTarget.dataset.index
    })
    that.getWrongTopicList(_banners[e.currentTarget.dataset.index].id);
  }
})